home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / lack.zoo / lacc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-01  |  10.4 KB  |  389 lines

  1. #include "lack.h"
  2. #include "vaproto.h"
  3. #include <string.h>
  4. #include <mintbind.h>
  5. #include <memory.h>
  6. extern char *getenv(char *);
  7. char **environ;
  8.  
  9. ki;
  10. extern int apid;
  11. extern int aes_version;
  12. extern int get_menu_title;
  13. extern lap *lapps[];
  14. extern lap *curapp;
  15.  
  16. /* fs.c: */
  17. long launch_prg(char *name, char *args);
  18.  
  19. /* trap2.c: */
  20. void get_gem_stack(void);
  21. int  check_for_desk(int was_desk);
  22. int  install_trap2(void);
  23.  
  24. struct name_mess
  25. {
  26.     int type;
  27.     int from;
  28.     int length;
  29.     char *name;
  30.     int domain;
  31.     int prg;
  32. };
  33.  
  34. #define LACK_ITEM "  you lack an acc    "
  35. #define CONT_ITEM "  Lack Control       "
  36. #define TIMER     200
  37. /* milliseconds between lackontrol's evnt_multi calls, this _really_ slows
  38.  * things down right now, so a larger value may be preferred */
  39.  
  40. const char *globs[2][2]={"*.AC?", "*.ac?", "*.PRG", "*.prg"};
  41. const char *prompts[2][2]={"ackessory to load",
  42.               "MiNT domain ackessory to load",
  43.               "program to load",
  44.               "program to load"
  45. };
  46.  
  47. const char kill_string[]="  kill acc:";
  48.  
  49. OBJECT rs_object[] = {
  50. -1, 1, 5, G_BOX, NONE, NORMAL, 0xff1100L, 0,0, 22,5,
  51. 2, -1, -1, G_STRING, NONE, DISABLED, (long)kill_string, 0,0, 22,1,
  52. 3, -1, -1, G_STRING, NONE, NORMAL, 0x1L, 0,1, 22,1,
  53. 4, -1, -1, G_STRING, NONE, NORMAL, 0x2L, 0,2, 22,1,
  54. 5, -1, -1, G_STRING, NONE, NORMAL, 0x3L, 0,3, 22,1,
  55. 6, -1, -1, G_STRING, NONE, NORMAL, 0x4L, 0,4, 22,1,
  56. 0, -1, -1, G_STRING, LASTOB, NORMAL, 0x5L, 0,5, 22,1};
  57. #define NUM_OBJ 7
  58. #define FIRST_SLOT 2
  59. #define LAST_SLOT 6
  60.  
  61. int deskx, desky, deskw, deskh;
  62. int charw, charh, boxw, boxh;
  63.  
  64. int
  65. popup(MENU_T *me_menu, int me_xpos, int me_ypos, MENU_T *me_mdata)
  66. {
  67.     OBJECT *tree=me_menu->mn_tree;
  68.     int start=me_menu->mn_menu;
  69.     int width, height, handle;
  70.     int mousex, mousey, keystate;
  71.     int event, m1_flag, m1_x, m1_y, m1_w, m1_h;
  72.     int junk, cur_obj=0, old_obj=0;
  73.     int oldx, oldy;
  74.  
  75.     width=tree[start].ob_width;
  76.     height=tree[start].ob_height;
  77.     oldx=tree[start].ob_x;
  78.     oldy=tree[start].ob_y;
  79.     if((me_xpos + width)  > (deskx + deskw)) me_xpos=deskx + deskw - width;
  80.     if((me_ypos + height) > (desky + deskh)) me_ypos=desky + deskh - height;
  81.     if(me_xpos < deskx) me_xpos=deskx;
  82.     if(me_ypos < desky) me_ypos=desky;
  83.     tree[start].ob_x=me_xpos;
  84.     tree[start].ob_y=me_ypos;
  85.     wind_update(BEG_MCTRL);
  86.     form_dial(FMD_START, me_xpos - 1, me_ypos -1, width + 2, height + 2,
  87.               me_xpos - 1, me_ypos -1, width + 2, height + 2);
  88.     objc_draw(tree, start, 1, me_xpos - 1, me_ypos -1, width + 2, height + 2);
  89.     graf_mkstate(&mousex, &mousey, &junk, &junk);
  90.     event=MU_M1;
  91.     while(1)
  92.     {
  93.         if(event & MU_M1)
  94.         {
  95.             if(cur_obj) /* deselect old cur_obj */
  96.         objc_change(tree, cur_obj, 0, me_xpos, me_ypos, width, height,
  97.                     tree[cur_obj].ob_state ^ SELECTED, 1);
  98.         old_obj=cur_obj;
  99.         cur_obj=objc_find(tree, start, 1, mousex, mousey);
  100.         if(cur_obj==-1)
  101.         {
  102.             m1_flag=0;
  103.             m1_x=me_xpos;
  104.             m1_y=me_ypos;
  105.             m1_w=width;
  106.             m1_h=height;
  107.             cur_obj=0;
  108.         }else{
  109.         m1_flag=1;
  110.             m1_x=me_xpos+tree[cur_obj].ob_x;
  111.             m1_y=me_ypos+tree[cur_obj].ob_y;
  112.             m1_w=tree[cur_obj].ob_width;
  113.             m1_h=tree[cur_obj].ob_height;
  114.             if(tree[cur_obj].ob_state & DISABLED) cur_obj=0;
  115.             else objc_change(tree, cur_obj, 0, me_xpos, me_ypos, width, height,
  116.                      tree[cur_obj].ob_state | SELECTED, 1);
  117.         }
  118.     }
  119.     if(event & MU_BUTTON) break;
  120.     event=evnt_multi(MU_BUTTON | MU_M1,
  121.              1, 1, 1,    /* mouse clicks, should allow pull down */
  122.              m1_flag, m1_x, m1_y, m1_w, m1_h,
  123.              0, 0, 0, 0, 0, /* mouse rect 2, do submenu */
  124.              (void *)0,     /* mesag */
  125.              0L,            /* timer */
  126.              &mousex, &mousey,
  127.              &junk, &keystate,/* button state, keystate */
  128.              &junk, &junk     /* keycode, number button events */
  129.              );
  130.     }
  131.     if(me_menu != me_mdata) *me_mdata=*me_menu;
  132.     me_mdata->mn_item=cur_obj;
  133.     me_mdata->mn_keystate=keystate;
  134.     tree[start].ob_x=oldx;
  135.     tree[start].ob_y=oldy;
  136.     if(cur_obj) tree[cur_obj].ob_state ^= SELECTED;
  137.     form_dial(FMD_FINISH, me_xpos - 1, me_ypos -1, width + 2, height + 2,
  138.               me_xpos - 1, me_ypos -1, width + 2, height + 2);
  139.     wind_update(END_MCTRL);
  140.     return (cur_obj ? 1 : 0);
  141. }
  142.  
  143. typedef struct __acc_menu
  144. {
  145.     int apid;
  146.     int obj;
  147.     struct __acc_menu *next;
  148. }acc_menu;
  149.  
  150. kill_acc_menu(myid)
  151. {
  152.     int i, cur_obj=FIRST_SLOT-1;
  153.     int x, y, junk;
  154.     int old_next, old_height;
  155.     MENU_T men={rs_object, 0, 1, 0, 0};
  156.     acc_menu *accs, *end;
  157.     int mess[8]={AC_OPEN, myid, 0, 0, 0, 0, 0, 0};
  158.     
  159.     accs=end=alloca(sizeof(acc_menu));
  160.     accs->obj=0;
  161.     for (i=myid - 1; i>=2; i--)
  162.     {
  163.         if(lapps[i])
  164.           if(!lapps[i]->acc->free)
  165.           {
  166.               end->next=alloca(sizeof(acc_menu));
  167.               end=end->next;
  168.               end->apid=i;
  169.               end->obj=++cur_obj;
  170.               rs_object[cur_obj].ob_spec=(long)&lapps[i]->acc->menu_title;
  171.           }
  172.     }
  173.     old_next=rs_object[cur_obj].ob_next;
  174.     rs_object[cur_obj].ob_next = 0;
  175.     rs_object[0].ob_tail=cur_obj;
  176.     old_height=rs_object[0].ob_height;
  177.     rs_object[0].ob_height=charh * (cur_obj - FIRST_SLOT + 2);
  178.     graf_mkstate(&x, &y, &junk, &junk);
  179.     if(popup(&men, x, y, &men))
  180.     {
  181.         while(accs->obj < men.mn_item) accs=accs->next;
  182.         if(accs->obj != men.mn_item)
  183.             form_alert(1, "[3][can't find selected item][ oh shit ]");
  184.         else{
  185.             lapps[accs->apid]->action=APPL_KILL;
  186.             appl_write(accs->apid, 16, mess);
  187.         }
  188.     }
  189.     rs_object[cur_obj].ob_next=old_next;
  190.     rs_object[0].ob_tail=LAST_SLOT;
  191.     rs_object[0].ob_height=old_height;
  192. }
  193.  
  194. int
  195. start_acc(char *name, int dom, int prgflag)
  196. {
  197.     int to_pid=2;
  198.     struct name_mess mess={LA_LOAD_ACC, apid, 0, name, dom, prgflag};
  199.  
  200.     for(;to_pid<NUM_APPS; to_pid++)
  201.         if(lapps[to_pid] && lapps[to_pid]->acc)
  202.             if(lapps[to_pid]->acc->free)
  203.                 break;
  204.     if(to_pid==NUM_APPS) 
  205.     {
  206.         form_alert(1, "[0][lack: no empty acc slots][ Bobdammit! ]");
  207.         return -1;
  208.     }
  209.     lapps[to_pid]->acc->free=FALSE;
  210.     appl_write(to_pid, 16, (int *)&mess);
  211.     mess.type=AC_OPEN;
  212.     ((int *)&mess)[3]=lapps[to_pid]->acc->menu_index;
  213.     appl_write(to_pid, 16, (int *)&mess);
  214. }
  215.  
  216. void
  217. interface(BASEPAGE *b)
  218. {
  219.     NEW_AESP(a);
  220.     lap *me;
  221.     struct lacc *acc;
  222.     int c, ok=1;
  223.     int keys, r, junk; /* evnt_multi stuff */
  224.     int mydom, dom, prg;
  225.     struct name_mess mess;
  226.     char first_path[128];
  227.     char *path;
  228.     char *end_first_path=&first_path[0];
  229.     char fname[33];
  230.     
  231.  
  232.     apid=cur_apid;
  233.     me=curapp;
  234.     acc=me->acc;
  235.     Syield(); Syield();
  236.     Pdomain(0);
  237.     environ=(char **)Dcntl(LA_BUILD_ENV, "S:", b->p_env);
  238.     get_gem_stack();
  239.     _aesparams=&a;
  240.     install_trap2();
  241.     apid=appl_init();
  242.     aes_version=a.global[0];
  243.     if(cur_apid != apid)
  244.         form_alert(0,"[3][lack: I can't find gem's|current application structure][ anything but that ]");
  245.     aes_version=a.global[0];
  246.     strncpy(acc->myname, aes_appl->name, 8);
  247.     acc->free=FALSE;
  248.     strcpy(acc->menu_title, CONT_ITEM);
  249.     get_menu_title=TRUE;
  250.     acc->menu_index=menu_register(apid, acc->menu_title);
  251.     get_menu_title=FALSE;
  252.  
  253.     graf_handle(&charw, &charh, &boxw, &boxh);
  254.     wind_get(0, WF_WORKXYWH, &deskx, &desky, &deskw, &deskh);
  255.     rsrc_saddr(R_OBJECT, 0, (char *)&rs_object[0]);
  256.     for(c=0; c< NUM_OBJ; c++)
  257.         rsrc_obfix(rs_object, c);
  258.  
  259.     bzero(first_path, 128);
  260.     bzero(fname, 33);
  261.     path=getenv("PATH");
  262.     if(!path)
  263.         if(!shel_envrn(&path, "PATH=")) path=NULL;
  264.     if(path)
  265.     {
  266.           /* it is always a good idea to keep gem programs in the first
  267.                * directory of the path, so this is the default place to find
  268.                * acc's.
  269.                */
  270.         if(*path=='/')
  271.         /* I cannot believe tcsh leaves the PATH in this format!! */
  272.         {
  273.             end_first_path=strcpy(first_path, "U:");
  274.             end_first_path+=2;
  275.         while(*path != ':' && *path != ',' && *path != ';')
  276.         {
  277.             if(*path=='/')
  278.             {
  279.                  *end_first_path++='\\';
  280.                  path++;
  281.             }else *end_first_path++ = *path++;
  282.         }
  283.         }else
  284.         while(*path != ',' && *path != ';') *end_first_path++ = *path++;
  285.         if(*(end_first_path-1)!='\\') *end_first_path++='\\';
  286.     }else{ /* no damn path anywhere */
  287.         strcpy(first_path, "U:\\");
  288.         end_first_path=first_path+3;
  289.     }
  290.  
  291.     while(1)
  292.     {
  293.     r=evnt_multi(MU_MESAG | MU_TIMER | MU_M1,
  294.                  0, 0, 0,       /* mouse button */
  295.                  0, 0, 16, 1, 1,/* mouse rect 1 */
  296.                  0, 0, 0, 0, 0, /* mouse rect 2 */
  297.                  (int *)&mess,  /* message buf  */
  298.                  TIMER,         /* timer        */
  299.                  &junk, &junk,  /* mouse pos    */
  300.                  &junk,         /* mouse buttons*/
  301.                  &keys,         /* keyshift     */
  302.                  &junk, &junk   /* keycode and number of mouse clicks */
  303.                 );
  304.     if(r & MU_MESAG)
  305.     {
  306.       switch(mess.type)
  307.       {
  308.         case AC_OPEN:
  309.             if(keys & 4) kill_acc_menu(apid);
  310.             else{
  311.             mydom=Pdomain(-1);
  312.             dom=(keys & 3)? 1 : 0;
  313.             prg=(keys & 8)? 1 : 0;
  314.             strcpy(end_first_path, globs[prg][mydom]);
  315.             wind_update(BEG_UPDATE);
  316.             wind_update(BEG_MCTRL);
  317.             fsel_exinput(first_path, fname, &ok, prompts[prg][dom]);
  318.             wind_update(END_UPDATE);
  319.             wind_update(END_MCTRL);
  320.             end_first_path=first_path+strlen(first_path);
  321.             while(*(end_first_path - 1) != '\\') end_first_path--;
  322.             strcpy(end_first_path, fname);
  323.             if(ok) start_acc(first_path, dom, prg);
  324.         }
  325.         break;
  326.         case AC_CLOSE:
  327.         {
  328.             long ssp;
  329.  
  330.             /*appl_yield();*/ evnt_timer(20);
  331.             ssp=Super(0);
  332.             check_for_desk(FALSE);
  333.             Super(ssp);
  334.             break;
  335.         }
  336.         case VA_START:
  337.             start_acc(mess.name, 0, 0); break;
  338.       }
  339.     }
  340.     }
  341. }
  342.  
  343. void
  344. empty_acc(BASEPAGE *b)
  345. {
  346.     NEW_AESP(a);
  347.     struct name_mess mess;
  348.     lap *me;
  349.     struct lacc *acc;
  350.     int ret;
  351.  
  352.     Syield(); Syield(); /* let the caller wake up */
  353.     get_gem_stack();
  354.     _aesparams=&a;
  355.     me=curapp;
  356.     acc=me->acc;
  357.     acc->free=TRUE;
  358.     appl_init();
  359.     strncpy(acc->myname, aes_appl->name, 8);
  360.     strcpy(acc->menu_title, LACK_ITEM);
  361.     get_menu_title=TRUE;
  362.     acc->menu_index=menu_register(apid, acc->menu_title);
  363.     get_menu_title=FALSE;
  364.  
  365.     while(1)
  366.     {
  367.         evnt_mesag((int *)&mess);
  368.         if(mess.type==LA_LOAD_ACC)
  369.         {
  370.             acc->free=FALSE;
  371.             if(mess.prg)
  372.             {
  373.                 acc->isprg=TRUE;
  374.                 ret=launch_prg(mess.name, "");
  375.                 acc->isprg=FALSE;
  376.                 graf_mouse(0, 0);
  377.             }else{
  378.                 Pdomain(mess.domain);
  379.                 ret=(short)Dcntl(LA_LOAD_ACC, "S:", mess.name);
  380.             }
  381.             if (ret<0) form_alert(1,"[1][lack: error starting acc][ huh ]");
  382.             acc->free=TRUE;
  383.             _aesparams=&a;
  384.             strncpy(aes_appl->name, acc->myname, 8);
  385.             strcpy(acc->menu_title, LACK_ITEM);
  386.         }
  387.     }
  388. }
  389.